<?php

	if (!defined("EXPONENT")) exit("");
	$article = null;
	if (isset($_GET['id'])) {
		$article = $db->selectObject("article","id=".$_GET['id']);
		if ($article != null) {
			$loc = unserialize($article->location_data);
			// get category ID
			if ($article->category_id == 0)
			{
				$temp=$db->selectObject('user','id = '. $article->ower_id);
				$article->name=$temp->firstname . " " . $temp->lastname;
			}
			else
			{
				$temp=$db->selectObject('category',"id = {$article->category_id}");
				if (!$temp)
					$article->name="";
				else
					$article->name=$temp->name;
			}
		} else {
			echo SITE_404_HTML;
		}
	}	
	// Aug 12. 2010: immanuel192 add this code to support view article by ajax
	$in_ajax=0;
	if (isset($_GET['ajax_action']) && ($_GET['ajax_action']==1)) {
		echo $_GET['t2'];
		$in_ajax=1;
	}
	// immanuel192 upgrade this module
	// to get it works well with new article module
	$value=$article; 
	$value->create_date=_ab_dateFormat($value->create_date,true);

	// for image
	//Get the image file if there is one.
	if (isset($value->image_id) && ($value->image_id > 0)) {
		$file = $db->selectObject('file', 'id='.$value->image_id);
		$value->image_path = $file->directory.'/'.$file->filename;
	}
	else
		$value->image_path="";


	if (isset($value->file_id) && ($value->file_id > 0)) {
		$file = $db->selectObject('file', 'id='.$value->file_id);
		//$value->file_path = BASE_URL.$file->directory.'/'.$file->filename;
		$value->file_path = $file->filename;
	}
	else
		$value->file_path="";

	// update
	$article=$value; 
	// update read_count value
	$db->increment("article","readcount",1,"id = " . $article->id);
	$article->readcount++;
	// Aug 12, 2010: immanuel192 add this code
	if ($in_ajax==0)
		$template = new template("articlemodule","_viewarticle",$loc);
	else
		$template = new template("articlemodule","_viewarticle_ajax",$loc);
	$template->assign('article', $article);
	exponent_flow_set(SYS_FLOW_PUBLIC,SYS_FLOW_ACTION);
	$template->register_permissions(array('manage'),$loc);
	$template->output();


?>
